package com.putong35.common.utils;

import android.content.Context;
import android.view.View;
import android.view.inputmethod.InputMethodManager;

import java.util.Timer;
import java.util.TimerTask;

/**
 * Created by ahong on 16/1/11.
 */
public class SoftInputUtil {

    /**
     * 显示/隐藏键盘
     */
    public static void hideSoftInputMode(final Context ctx, final View editText, boolean isHide) {
        final InputMethodManager imm = (InputMethodManager) ctx
                .getSystemService(Context.INPUT_METHOD_SERVICE);
        if (editText != null) {
            if (isHide) {
                imm.hideSoftInputFromWindow(editText.getWindowToken(), 0);
            } else {
                editText.setFocusable(true);
                editText.setFocusableInTouchMode(true);
                editText.requestFocus();
                Timer timer = new Timer();
                timer.schedule(new TimerTask() {
                    public void run() {
                        imm.showSoftInput(editText, InputMethodManager.SHOW_IMPLICIT);
                    }
                }, 500);
            }
        }
    }
}
